﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PdfLibrary
{
    public class SingletonDictionary
    {
        protected static Dictionary<Type, object> dictionary = new Dictionary<Type, object>();

        public static T Get<T>()
        {
            Type type = typeof(T);

            object obj;

            if (!dictionary.TryGetValue(type, out obj))
            {
                dictionary.Add(type, null);
                obj = Reset<T>();
            }

            return (T)obj;
        }

        public static T Reset<T>()
        {
            T obj = Activator.CreateInstance<T>();
            dictionary[typeof(T)] = obj;
            return obj;
        }
    }
}
